package com.gudaomai.wuye.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gudaomai.wuye.common.CommonException;
import com.gudaomai.wuye.entity.House;
import com.gudaomai.wuye.entity.HpStage;
import com.gudaomai.wuye.mapper.HouseMapper;
import com.gudaomai.wuye.service.IHouseServ;
import com.gudaomai.wuye.service.impl.BaseServiceImpl;

import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zenghualu
 * @since 2017-09-01
 */
@Service
public class HouseServImp extends BaseServiceImpl<HouseMapper, House> implements IHouseServ {

	// 判断住房是否存在
	@Override
	public boolean isExist(String code) {

		EntityWrapper<House> ew = new EntityWrapper<>();
		ew.setEntity(new House());
		ew.eq("code", code);

		House house = this.selectOne(ew);
		if (null == house) {
			return false;
		}

		return true;
	}

	// // 获取住房详细编号--阶梯形式
	@Override
	public List<HpStage> getHousesByRegionCode(String code) throws CommonException {

		List<HpStage> stages = this.baseMapper.selectHousesByRegionCode(code);

		if (stages.size() > 0) {
			return stages;
		}

		return null;
	}

	// 获取住房详细编号--列表形式
	@Override
	public List<House> getListHousesByRegionCode(List<String> code) throws CommonException {
		
		List<House> houses = this.baseMapper.selectListHousesByRegionCode(code);
		
		if (houses.size() > 0) {
			return houses;
		}
		
		return null;
	}

}
